package com.sjzd.meeting.dao;

import com.sjzd.meeting.pojo.MeetingGrab;
import com.sjzd.meeting.pojo.MeetingPublish;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * MeetingGrabDAO继承基类
 */
@Mapper
public interface MeetingGrabDAO extends MyBatisBaseDao<MeetingGrab, String> {

    /**
     * -- 根据用户传来的uid(用户id)和tid(讲座类型)进行相应查询，要求如下：
     * 	-- 1.查询到的订单所要求的区域要与用户所在地域与一致
     * 	-- 2.查询到的订单一定要与用户查询的类别一致
     * 	-- 3.查询的结果中不能含有用户已抢过的订单
     * 	-- 4.订单必须是可匹配状态（0：可抢， 1，2： 不可抢 ）
     *     -- 5.订单必须是有效状态
     *  select pub.* from meeting_publish pub
     *     left join meeting_grab grab on grab.mid = pub.id
     *     join user u on u.id = #{uid} and (pub.zone = u.zone or pub.zone='全国')
     *     where pub.status = 1 and (grab.uid != #{uid}  or grab.uid is null) and (grab.match_status != 1 or grab.match_status is null)
     *     <if test="tid != 0">
     *       and pub.tid = #{tid}
     *     </if>
     *
     * @param uid
     * @param tid
     * @return
     */
    List<MeetingPublish> selectByUidAndTid(Integer uid, Integer tid);

    /**
     *  查询某人已抢订单
     * @param uid
     * @return
     */
    List<MeetingGrab> selectByUid(Integer uid);

    int updateByIdAndMid(MeetingGrab meetingGrab);

    @Update("update meeting_grab set match_status = 2 where mid = #{mid} and id != #{id}")
    int updateFailOrderMatchStatusByIdAndMid(String id, String mid);

    List<MeetingGrab> selectCandidateByMid(String mid);
}